/*
This source file is subject to the GPLv3 license that is bundled with this
package in the file LICENSE.txt.
It is also available through the world-wide-web at this URL:
http://www.gnu.org/licenses/gpl.txt
*/

/*==============================================================================
  File Name   : main.cpp
  Description : Tester program for GNetwork module of gUtil.

  Created on  : 2009-06-04
  Updated on  : 2009-06-10
  Updated by  : Shiou Ming, Lee

  Cautions    : (important notes)
  ============================================================================*/

//------------------------------------------------------------------------------
//-- INCLUDES & DEFINES
//------------------------------------------------------------------------------
#include <stdio.h>
#include "../GNetwork.h"

#define APP_NAME_     "GNetwork module tester"
#define APP_VERSION_  "1.0.0.3"


//------------------------------------------------------------------------------
//-- TYPEDEF / STRUCT / UNION / ENUM
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//-- GLOBAL
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//-- FUNCTION PROTOTYPES
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//-- MAIN FUNCTION
//------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
    printf("\n=== %s, version %s ===\n\n", APP_NAME_, APP_VERSION_);

    TCPClientSocket *socket1 = NULL;
    TCPClientSocket *socket2 = NULL;
    TCPClientSocket *socket3 = NULL;

    // Create TCP client socket with specific remote address
    socket1 = new TCPClientSocket("127.0.0.1", 9999);

    // Create TCP client socket, but set remote address later on
    socket2 = new TCPClientSocket();
    socket2->setRemoteAddress("127.0.0.1", 9998);

    // Connect to a TCP server
    socket1->connectServer();
    socket2->connectServer();
    socket3 = new TCPClientSocket();
    socket3->connectServer("127.0.0.1", 9997);

    // Send text data to connected TCP server
    socket1->sendTextData("Test data... muahahah");

    // Attempt to receive any text data from TCP server
    char dataBuffer[0];
    memset(dataBuffer, 0, sizeof(dataBuffer));
    socket1->receiveTextData(dataBuffer, sizeof(dataBuffer));

    // Cleanup
    if (NULL != socket1)
    {
        delete socket1;
        socket1 = NULL;
    }

    if (NULL != socket2)
    {
        delete socket2;
        socket2 = NULL;
    }

    if (NULL != socket3)
    {
        delete socket3;
        socket3 = NULL;
    }

	// Stop the console screen before quit for displaying the output.
    printf("\n\nPress <ENTER> key to exit");
    getchar();

    return 0;
}


//------------------------------------------------------------------------------
//-- FUNCTION IMPLEMENTATIONS
//------------------------------------------------------------------------------

